<?php

namespace JsonLowCode\Table;

use Closure;
use JsonLowCode\Schema;
use JsonLowCode\Support\Fluent;
use JsonLowCode\Table;

abstract class BaseAction extends Fluent
{
    /**
     * 表组件
     * @var Table
     */
    protected Table $table;

    protected ?Schema $element = null;

    protected ?Closure $closure = null;

    public string $rowDataField = "self.rowData";
    public string $rowDataIndex = "self.rowIndex";

    /**
     * @param Table $table
     */
    public function __construct(Table $table)
    {
        parent::__construct();
        $this->table = $table;
        list($rowDataField,$rowDataIndex) = $this->table->getRowData();
        $this->rowDataField = $rowDataField;
        $this->rowDataIndex = $rowDataIndex;
    }

    abstract protected function booted();

    public function toArray(): array
    {
        $this->booted();
        return $this->element->jsonSerialize();
    }
}
